﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MusicDatabase
{
    /*
     * Auteur:  Joris Molnár en Niels van Leusden
     * Datum:   31-1-2013
     * Omschrijving: Ongeveer gelijk aan de klasse AddAlbum, maakt deze klasse het mogelijk Artiesten toe te kunnen voegen.
     *               Dit gaat wederom niet direct, maar via de klasse Artist.
     *               Deze klasse bekijkt wel of de artiest niet reeds bestaat, in dat geval verschijnt een foutmelding.                    
     * 
     */
    public partial class AddArtist : Form
    {

        public AddArtist()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            tbName.Text = tbName.Text.Trim();
            tbActive.Text = tbActive.Text.Trim();
            tbOrigin.Text = tbOrigin.Text.Trim();
            tbNotes.Text = tbNotes.Text.Trim();
            tbBiography.Text = tbBiography.Text.Trim();

            if (ArtistExist(tbName.Text))
            {
                MessageBox.Show("This artist already exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string[] artistData = { tbName.Text, tbActive.Text, tbOrigin.Text, tbNotes.Text, tbBiography.Text };

            Artist artist = new Artist(artistData);
            artist.Save();
            this.Close();
        }

        /// <summary>
        /// Look if the artist already exist by name
        /// </summary>
        /// <param name="name">The name to look for</param>
        /// <returns></returns>
        private bool ArtistExist(string name)
        {
            Artist artist = new Artist();
            SQLServices sqlService = new SQLServices();
            return artist.Exist(sqlService, tbName.Text);
        }

        private void tbName_TextChanged(object sender, EventArgs e)
        {
            if (tbName.Text.Trim() == "")
            {
                btnAdd.Enabled = false;
            }
            else
            {
                btnAdd.Enabled = true;
            }
        }
    }
}
